﻿using AutoMapper;
using QuarryPlanner.Domain.DTOs;
using QuarryPlanner.Domain.Entities;
using QuarryPlanner.Domain.Interfaces.Domain;
using QuarryPlanner.Domain.Interfaces.Persistence;
using System;
using System.Collections.Generic;

namespace QuarryPlanner.Domain.Services
{
    // Author: Ryan Redburn
    // Created: 10/20/2014

    #region [ Updates ]

    // Author: Ryan Redburn
    // Date: 11/5/2014
    // Revision: Added methods for interacting with MobileVehicleExam.

    #endregion

    /// <summary>
    /// Service class used to interact with QuarryHours.
    /// </summary>
    public sealed class DailyReportService : IDailyReportService
    {
        #region [ Fields ]

        private readonly IDailyReportRepository _drRepo;

        #endregion

        #region [ Constructors ]

        /// <summary>
        /// Creates an instance of DailyReportService using the required repository.
        /// </summary>
        /// <param name="drRepo">IDailyReportRepository dependency.</param>
        public DailyReportService(IDailyReportRepository drRepo)
        {
            _drRepo = drRepo;
        }

        #endregion

        #region [ Methods ]

        #region [ QuarryHours ]

        /// <summary>
        /// Retrieves the QuarryHours with the given ID.
        /// </summary>
        /// <param name="id">QuarryHours ID.</param>
        /// <returns>QuarryHours.</returns>
        public QuarryHours GetQuarryHoursByID(int id)
        {
            if (id < 0)
                throw new ArgumentOutOfRangeException("id", "GetQuarryHoursByID does not accept an integer less than one as an argument.");

            return Mapper.Map<QuarryHours>(_drRepo.FindQuarryHoursByID(id));
        }

        /// <summary>
        /// Retrieves all QuarryHours.
        /// </summary>
        /// <returns>List of QuarryHours.</returns>
        public List<QuarryHours> GetAllQuarryHours()
        {
            return Mapper.Map<List<QuarryHours>>(_drRepo.FindAllQuarryHours());
        }

        /// <summary>
        /// Saves a new QuarryHours report.
        /// </summary>
        /// <param name="quarryHours">New QuarryHours to save.</param>
        public void Save(QuarryHours quarryHours)
        {
            if (quarryHours == null)
                throw new ArgumentNullException("quarryHours", "SaveQuarryHours does not accept a null QuarryHoursDTO as an argument.");

            _drRepo.Insert(Mapper.Map<QuarryHoursDTO>(quarryHours));
        }

        /// <summary>
        /// Deletes an existing QuarryHours report.
        /// </summary>
        /// <param name="quarryHours">QuarryHours to delete.</param>
        public void Delete(QuarryHours quarryHours)
        {
            if (quarryHours == null)
                throw new ArgumentNullException("quarryHours", "DeleteQuarryHours does not accept a null QuarryHoursDTO as an argument.");

            _drRepo.Delete(Mapper.Map<QuarryHoursDTO>(quarryHours));
        }

        #endregion

        #region [ MVE ]

        /// <summary>
        /// Retrieves the MVE with the given ID.
        /// </summary>
        /// <param name="id">MVE ID.</param>
        /// <returns>MobileVehicleExam.</returns>
        public MobileVehicleExam GetMVEByID(int id)
        {
            if (id < 0)
                throw new ArgumentOutOfRangeException("id", "GetMVEByID does not accept an integer less than one as an argument.");

            return Mapper.Map<MobileVehicleExam>(_drRepo.FindMVEByID(id));
        }

        /// <summary>
        /// Retrieves all MVEs.
        /// </summary>
        /// <returns>List of MobileVehicleExam.</returns>
        public List<MobileVehicleExam> GetAllMVE()
        {
            return Mapper.Map<List<MobileVehicleExam>>(_drRepo.FindAllMVE());
        }

        /// <summary>
        /// Saves the given MVE.
        /// </summary>
        /// <param name="mve">MobileVehicleExam to save.</param>
        public void Save(MobileVehicleExam mve)
        {
            if (mve == null)
                throw new ArgumentNullException("mve",
                    "Save does not accept a null MobileVehicleExam as an argument.");

            _drRepo.Insert(Mapper.Map<MobileVehicleExamDTO>(mve));
        }

        /// <summary>
        /// Deletes the existing MVE.
        /// </summary>
        /// <param name="mve">MobileVehicleExam to delete.</param>
        public void Delete(MobileVehicleExam mve)
        {
            if (mve == null)
                throw new ArgumentNullException("mve",
                    "Delete does not accept a null MobileVehicleExam as an argument.");

            _drRepo.Delete(Mapper.Map<MobileVehicleExamDTO>(mve));
        }

        #endregion

        #region [ WPE ]

        /// <summary>
        /// Retrieves the WPE with the given ID.
        /// </summary>
        /// <param name="id">WPE ID.</param>
        /// <returns>WorkPlaceExam.</returns>
        public WorkPlaceExam GetWPEByID(int id)
        {
            if (id <= 0)
                throw new ArgumentOutOfRangeException("id", "GetWPEByID does not accept an integer less than one as an argument.");

            return Mapper.Map<WorkPlaceExam>(_drRepo.FindWPEByID(id));
        }

        /// <summary>
        /// Retrieves all WPE.
        /// </summary>
        /// <returns>List of WorkPlaceExam.</returns>
        public List<WorkPlaceExam> GetAllWPE()
        {
            return Mapper.Map<List<WorkPlaceExam>>(_drRepo.FindAllWPE());
        }

        /// <summary>
        /// Saves the given WPE.
        /// </summary>
        /// <param name="wpe">New WorkPlaceExam to save.</param>
        public void Save(WorkPlaceExam wpe)
        {
            if (wpe == null)
                throw new ArgumentNullException("wpe",
                    "Delete does not accept a null WorkPlaceExam as an argument.");

            _drRepo.Insert(Mapper.Map<WorkPlaceExamDTO>(wpe));
        }

        /// <summary>
        /// Deletes an existing WPE.
        /// </summary>
        /// <param name="wpe">WorkPlaceExam to delete.</param>
        public void Delete(WorkPlaceExam wpe)
        {
            if (wpe == null)
                throw new ArgumentNullException("wpe",
                    "Delete does not accept a null WorkPlaceExam as an argument.");

            _drRepo.Delete(Mapper.Map<WorkPlaceExamDTO>(wpe));
        }

        #endregion

        #endregion
    }
}
